package com.travelshare.web.controller.business;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.travelshare.business.domain.ColumnDetail;
import com.travelshare.business.domain.InfoColumn;
import com.travelshare.business.domain.app.LbtData;
import com.travelshare.business.service.IColumnDetailService;
import com.travelshare.business.service.IInfoColumnService;
import com.travelshare.common.core.controller.BaseController;
import com.travelshare.common.core.domain.AjaxResult;
import com.travelshare.framework.config.ServerConfig;

@RestController
@RequestMapping("/appIndex")
public class AppIndexController extends BaseController {

	@Autowired
	private IColumnDetailService columnDetailService;

	@Autowired
	private IInfoColumnService infoColumnService;

	@Autowired
	private ServerConfig serverConfig;

	@RequestMapping("/lbt")
	public AjaxResult lbt(ColumnDetail columnDetail) {
		List<LbtData> list = columnDetailService.selectLbtData(columnDetail);
		if (!list.isEmpty()) {
			String url = serverConfig.getUrl() + "/profile";
			for (LbtData c : list) {
				if (c.getPicPath().startsWith("/profile")) {
					String picPath = c.getPicPath().replaceAll("/profile", url);
					c.setPicPath(picPath);
				}
			}
		}
		return success(list);
	}

	@RequestMapping("/getShare")
	public AjaxResult getShare(ColumnDetail columnDetail) {
		startPage();
		columnDetail.setIsShare(1);
		columnDetail.setState("Y");
		columnDetail.setUserIds(getUserId());
		List<ColumnDetail> list = columnDetailService.selectColumnDetailList(columnDetail);
		return success(list);
	}

	@RequestMapping("/getList")
	public AjaxResult getList(ColumnDetail columnDetail) {
		InfoColumn infoColumn = new InfoColumn();
		infoColumn.setIsIndex("Y");
		infoColumn.setState("0");
		List<InfoColumn> cList = infoColumnService.selectInfoColumnList(infoColumn);
		columnDetail.setState("Y");
		columnDetail.setUserIds(getUserId());
		Map<String, List<ColumnDetail>> map = new LinkedHashMap<String, List<ColumnDetail>>();
		if (!cList.isEmpty()) {
			for (InfoColumn cm : cList) {
				startPage();
				columnDetail.setColumnId(cm.getColumnId());
				List<ColumnDetail> list = columnDetailService.selectColumnDetailList(columnDetail);
				map.put(cm.getColumnName(), list);
			}
		}

		return success(map);
	}

}
